package com.taijia.chapter8;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

/**
 * TestBufferStream2
 * 
 * @author taijia
 * @since 2014年11月25日
 *
 */
public class TestBufferStream2 {
	public static void main(String[] args) {
		BufferedWriter bw = null;
		BufferedReader br = null;
		try {
			bw = new BufferedWriter(new FileWriter("E:/myeclipse2014/Workspaces/2014/msb_basic/src/com/taijia/chapter8/TestBufferStream2.txt"));
			br = new BufferedReader(new FileReader("E:/myeclipse2014/Workspaces/2014/msb_basic/src/com/taijia/chapter8/TestBufferStream2.txt"));
			String s;
			for (int i = 0; i < 20; i++) {
				s = String.valueOf(new Random().nextInt(65535));
				bw.write(s);
				bw.newLine();
			}
			bw.flush(); //
			// readLine 直接读一行出来
			while ((s=br.readLine()) != null) {
				System.out.println(s);
			}
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(-1);
		} finally {
			try {
				br.close();
				bw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
